<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/15
 * Time: 15:01
 */

namespace Home\Controller;
use Think\Controller;
use Home\Model\UserModel;

class InviteController extends BaseController {

    public function index()
    {
//       $user_id = 276;
        $type = I('get.type');
        $user_id = I('get.user_id');
        $Invite = new UserModel();
        $data = $Invite->invite_times($user_id);
        $income = $Invite->get_income($user_id);
        $data['total_income'] = $income;
        $url = "http://www.520welove.com/index/invite_friend";
        $data['url'] = $url."?user_id=$user_id"."&type=$type";
        $sum = $Invite->get_draw_account($user_id);
        $data['already_draw'] = $sum;
        if(empty($data['already_draw']))
        {
            $data['already_draw']='';
        }
        if(empty($data['active_times']))
        {
            $data['active_times'] = 0;
        }
        echo json_encode($data);
    }

    public function income_detail()
    {
//        $user_id = 276;
        $user_id = I('get.user_id');
        $Invite = new UserModel();
        $data = $Invite->invite_times($user_id);
        $income = $Invite->get_income($user_id);
        $detail = $Invite->get_income_detail($user_id);
        $data['total_income'] = $income;
        $data['income_detail'] = $detail;
        if(empty($data['active_times']))
        {
            $data['active_times'] = 0;
        }
        echo json_encode($data);
    }
}